import { CrudOptions, AddReq, DelReq, EditReq, dict, CrudExpose, UserPageQuery, CreateCrudOptionsRet} from '@fast-crud/fast-crud';
import _ from 'lodash-es';
import * as api from './api';
import { request } from '/@/utils/service';
import {auth} from "/@/utils/authFunction";

//此处为crudOptions配置
export default function ({ crudExpose}: { crudExpose: CrudExpose}): CreateCrudOptionsRet {
	const pageRequest = async (query: any) => {
		return await api.GetList(query);
	};
	const editRequest = async ({ form, row }: EditReq) => {
		if (row.id) {  
			form.id = row.id;
		}
		return await api.UpdateObj(form);
	};
	const delRequest = async ({ row }: DelReq) => {
		return await api.DelObj(row.id);
	};
	const addRequest = async ({ form }: AddReq) => {
		return await api.AddObj(form);
	};

    const exportRequest = async (query: UserPageQuery) => {
		return await api.exportData(query)
	};

	return {
		crudOptions: {
			request: {
				pageRequest,
				addRequest,
				editRequest,
				delRequest,
			},
			actionbar: {
				buttons: {
						export:{
                            // 注释编号:django-vue3-admin-crud210716:注意这个auth里面的值，最好是使用index.vue文件里面的name值并加上请求动作的单词
                            show: auth('PartModelViewSet:Export'),
                            click(){
                                return exportRequest(crudExpose.getSearchFormData())
                            }
                        },
                        add: {
                            show: auth('PartModelViewSet:Create'),
                        },
				}
			},
            rowHandle: {
                //固定右侧
                fixed: 'right',
                width: 200,
                buttons: {
                    view: {
                        type: 'text',
                        show: auth('PartModelViewSet:Retrieve')
                    },
                    edit: {
                        type: 'text',
						show: auth('PartModelViewSet:Update')
                    },
                    remove: {
                        type: 'text',
						show: auth('PartModelViewSet:Delete')
                    },
                },
            },
			columns: {
				uuid: {
					title: '平台ID',
					type: 'input',
					search: { show: true},
					column: {
						minWidth: 120,
						sortable: 'custom',
					},
					form: {
						helper: {
							render() {
								return <div style={"color:blue"}>平台ID是必需要填写的</div>;
								}
							},
						rules: [{ required: true, message: '平台ID必填' }],
						component: {
							placeholder: '请输入平台ID',
						},
					},
				},
                platformname: {
					title: '平台名称',
					type: 'text',
					// type: 'number',
					search: { show: false },
					column: {
						minWidth: 120,
						sortable: 'custom',
					},
					form: {
						rules: [{ required: true, message: '平台名称必填' }],
						component: {
							placeholder: '请输入平台名称',
						},
					},
				},

                platformcode: {
					title: '平台代码',
					type: 'text',
					search: { show: false },
					column: {
						minWidth: 120,
						sortable: 'custom',
					},
					form: {
						rules: [{ required: true, message: '平台代码必填' }],
						component: {
							placeholder: '请输入平台代码',
						},
					},
				},

				// remark: {
				// 	title: '平台描述',
				// 	type: 'text',
				// 	search: { show: false },
				// 	column: {
				// 		minWidth: 120,
				// 		sortable: 'custom',
				// 	},
				// 	form: {
				// 		rules: [{ required: false, message: '平台描述必填' }],
				// 		component: {
				// 			placeholder: '请输入平台描述',
				// 		},
				// 	},
				// },
                // purchase_goods_date: {
                //     title: '进货时间',
				// 	type: 'date',
				// 	search: { show: false },
                //     form: {
                //     // rules: [{ required: true, message: '进货时间必填' }],
                //       component: {
                //             //显示格式化
                //             format: "YYYY-MM-DD",
                //             //输入值格式
                //             valueFormat: "YYYY-MM-DD",
                //             placeholder: '请输入进货时间',
                //       }
                //     },
                //     column: {
                //       align: "center",
                //       width: 120,
                //       component: { name: "fs-date-format", format: "YYYY-MM-DD" }
                //     }
                //   },


			},
		},
	};
};